package service

import (
	"encoding/base64"
	"github.com/golang/protobuf/proto"
	cgapi "gitlab.vrviu.com/cloudgame_backend/access-public/grpc/com_pb"
	"gitlab.vrviu.com/inviu/backend-go-public/gopublic"
	"time"
)

func (client *AreaClient) getCGReqLaunchGame() *cgapi.CGReqLaunchGame {
	return &cgapi.CGReqLaunchGame{
		Header: &cgapi.CommonHeader{
			RequestId: gopublic.GenerateRandonString(8),
			Timestamp: uint64(time.Now().Unix()),
			Token:     client.Atoken,
		},
		GameId:       client.Gid,
		ResourceType: 1,
		StreamInfo:   "{\"avgBitrateratio\":100,\"cameraInfo\":{\"cameraBitrate\":850,\"cameraFps\":24,\"cameraHeight\":480,\"cameraId\":1,\"cameraLevel\":1,\"cameraWidth\":640},\"clientNetworkType\":40,\"clientSupportHevc\":0,\"clientType\":\"web-pc\",\"connectionType\":\"webrtcVideo\",\"desiredHeight\":1080,\"desiredWidth\":1920,\"dev_identity\":\"\",\"forceAudioDataChannel\":0,\"gid\":12882,\"idrPeriod\":60,\"imeType\":0,\"keyboardType\":0,\"maxFps\":30,\"packetSize\":768,\"policy\":\"{}\",\"requestUseServerCursorData\":true,\"supportVideoCodecProfiles\":[8,1],\"vibration\":true,\"videoDataType\":\"mp4.h264\",\"videoLevel\":3,\"withHWCursor\":false}",
	}
}

func (client *AreaClient) getPrelaunchParam() string {
	data, _ := proto.Marshal(client.getCGReqLaunchGame())
	return base64.StdEncoding.EncodeToString(data)
}

func (client *AreaClient) getHeartBeat() *cgapi.CGReqHeartbeat {
	return &cgapi.CGReqHeartbeat{
		Header: &cgapi.CommonHeader{
			RequestId: gopublic.GenerateRandonString(8),
			Timestamp: uint64(time.Now().Unix()),
			Token:     client.Atoken},
	}
}

func (client *AreaClient) getExitGame() *cgapi.CGReqExitGame {
	return &cgapi.CGReqExitGame{
		Header: &cgapi.CommonHeader{
			RequestId: gopublic.GenerateRandonString(8),
			Timestamp: uint64(time.Now().Unix()),
			Token:     client.Atoken,
		},
		GameId: client.Gid,
	}
}
